package com.szsky.sky.task;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.szsky.sky.config.UpdateAttendanceSignConfig;
import com.szsky.sky.dto.AttendancePersonnelUnitDto;
import com.szsky.sky.dto.EmployeeDto;
import com.szsky.sky.dto.OaInSpurUserDto;
import com.szsky.sky.entity.AttendanceSignAndStatisticsConfigEntity;
import com.szsky.sky.entity.Gorganize;
import com.szsky.sky.entity.OaInspurOrganize;
import com.szsky.sky.entity.UmcPerson;
import com.szsky.sky.entity.UmcUsers;
import com.szsky.sky.mapper.*;
import com.szsky.sky.pojo.*;
import com.szsky.sky.utils.DateUtilJava8;
import com.szsky.sky.utils.HolidayUtils;
import com.szsky.sky.utils.ListUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 齐行
 * @version 1.0
 * @description:
 * @date 2025/6/11 16:42
 */

@Slf4j
@Component
public class Task {

    @Resource
    private EmployeeMapper employeeMapper;

    @Resource
    private GuserInfoMapper guserInfoMapper;

    @Resource
    private OaInSpurUserMapper oaInSpurUserMapper;

    @Resource
    private AttendanceSignMapper attendanceSignMapper;

    @Resource
    private AttendanceStatisticsMapper attendanceStatisticsMapper;

    @Resource
    private AttendanceCalendarMapper attendanceCalendarMapper;

    @Resource
    private OaInspurOrganizeMapper oaInspurOrganizeMapper;

    @Resource
    private GorganizeMapper gorganizeMapper;

    @Resource
    private EmpWorkPlanMapper empWorkPlanMapper;


    @Resource
    private UpdateAttendanceSignConfig updateAttendanceSignDto;

    @Resource
    private AttendancePersonnelUnitMapper attendancePersonnelUnitMapper;

    @Value("${synchronize.holidays}")
    private Boolean synchronizeHolidays;

    @Value("${synchronization.data.date}")
    private String synchronizationDataDate;

    @Value("${synchronization.isExecute}")
    private Boolean isExecute;

    @Resource
    private UmcPersonMapper umcPersonMapper;

    @Resource
    private UmcUserMapper umcUserMapper;


    /**
     * 显示挂职人员当天考勤，定时任务
     */
    @Schedules({
            @Scheduled(cron = "${spring-task.schedules.schedule1}"),
            @Scheduled(cron = "${spring-task.schedules.schedule2}")
    })
    private void executeHandleAttendanceDataOfTheSecondedUnit() {
        if (!isExecute){
            return;
        }else {
            handleAttendanceDataOfTheSecondedUnit();

        }
    }

    /**
     * 单位考勤统计(打卡统计)，数据从单位当日考勤汇总到单位考勤情况
     */
    //TODO 数据已经比对 无问题 执行顺序 1
    @Scheduled(cron = "${spring-task.cronSync}")
    private void clockCount() {
        if (!isExecute) {
            return;
        }

        // 判断是否为节假日或周末处理数据
        if (synchronizeHolidays) {
            handleClockCountData();
            unpunchedData();
            secondmentUnitsOfPerson();
//            noSignData2();
            log.info("单位考勤统计定时任务，执行完成！");
        } else {
            log.info("配置为周末或节假日不处理考勤数据");
            DateTime dateTime = null;

            if (StringUtils.isNotBlank(synchronizationDataDate)) {
                dateTime = DateUtil.parse(synchronizationDataDate);
            } else {
                dateTime = DateUtil.yesterday();
            }

            //判断是否为周末或节假日
            if (!HolidayUtils.isHolidayOrWeekend(DateUtil.format(dateTime, "yyyy-MM-dd"))) {
                // 不是周末
                log.info("不是周末或节假日");
                handleClockCountData();
                unpunchedData();
                secondmentUnitsOfPerson();
//                noSignData2();
            } else {
                log.info("周末或法定节假日不处理数据");
            }
        }
    }

    /**
     * 处理何智勇、刘健打卡问题
     */
    private void noSignData2() {
        DateTime yesterday = null;
        if (StringUtils.isNotBlank(synchronizationDataDate)) {
            yesterday = DateUtil.parse(synchronizationDataDate);
        } else {
            yesterday = DateUtil.yesterday();
        }


        log.info("昨天日期：{}", DateUtil.beginOfDay(yesterday));

        // 何智勇
        UpdateWrapper<AttendanceStatistics> updateAttendanceStatisticsWrapper = new UpdateWrapper<>();
        updateAttendanceStatisticsWrapper.set("crop_id", "O00000000000040162");
        updateAttendanceStatisticsWrapper.set("crop_name", "财务基建管理局");
        updateAttendanceStatisticsWrapper.set("dept_id", "O50000000000040002");
        updateAttendanceStatisticsWrapper.set("dept_name", "基建规划处");
        updateAttendanceStatisticsWrapper.set("uc_uid", "166e2bbb6c0e4d3194a13780c973800c");
        updateAttendanceStatisticsWrapper.eq("sign_date", DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
        updateAttendanceStatisticsWrapper.eq("uc_uid", "873535e55ace4cd2b48165377be45169");
        int update = attendanceStatisticsMapper.update(updateAttendanceStatisticsWrapper);
        if (update > 0) {
            log.info("何智勇考勤统计表修改完成");
        } else {
            log.info("何智勇考勤统计表未修改");
        }

        updateAttendanceStatisticsWrapper = new UpdateWrapper<>();
        updateAttendanceStatisticsWrapper.set("crop_id", "O00000000000040162");
        updateAttendanceStatisticsWrapper.set("crop_name", "财务基建管理局");
        updateAttendanceStatisticsWrapper.set("dept_id", "O50000000000040002");
        updateAttendanceStatisticsWrapper.set("dept_name", "基建规划处");
        updateAttendanceStatisticsWrapper.set("uc_uid", "f9556333835f4d9e9a9dbb0e330cccc9");
        updateAttendanceStatisticsWrapper.set("name", "刘健");
        updateAttendanceStatisticsWrapper.eq("sign_date", DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
        updateAttendanceStatisticsWrapper.eq("uc_uid", "dd054ee0042e4742b395f007751e6c89");
        update = attendanceStatisticsMapper.update(updateAttendanceStatisticsWrapper);
        if (update > 0) {
            log.info("刘健考勤统计表修改完成");
        } else {
            log.info("刘健考勤统计表未修改");
        }

    }


    /**
     * 单们考勤统计(打卡统计)，数据从单位当日考勤汇总到单位考勤情况
     */
    private void handleClockCountData() {
        String minStr = "";

        String maxStr = "";

        String middleStr = "";

        String queryDateStart = "";

        String queryDateEnd = "";

        List<AttendanceSignAndStatisticsConfigEntity> attendanceSignAndStatisticsDtoList = updateAttendanceSignDto.getAttendanceSignAndStatisticsDtoList();
        if (CollectionUtil.isNotEmpty(attendanceSignAndStatisticsDtoList)) {
            LambdaUpdateWrapper<AttendanceSign> lambdaUpdateWrapper = null;
            for (AttendanceSignAndStatisticsConfigEntity dto : attendanceSignAndStatisticsDtoList) {
                if (StringUtils.isNotBlank(dto.getOldUcUid()) && StringUtils.isNotBlank(dto.getUcUid())) {
                    lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
                    lambdaUpdateWrapper.set(AttendanceSign::getUcUid, dto.getUcUid());
                    lambdaUpdateWrapper.set(AttendanceSign::getName, dto.getName());
                    lambdaUpdateWrapper.set(AttendanceSign::getCropId, dto.getCropId());
                    lambdaUpdateWrapper.set(AttendanceSign::getCropName, dto.getCropName());
                    lambdaUpdateWrapper.set(AttendanceSign::getDeptId, dto.getDeptId());
                    lambdaUpdateWrapper.set(AttendanceSign::getDeptName, dto.getDeptName());
                    lambdaUpdateWrapper.eq(AttendanceSign::getUcUid, dto.getOldUcUid());
                    attendanceSignMapper.update(lambdaUpdateWrapper);
                }
            }
        }

        if (StringUtils.isNotBlank(synchronizationDataDate)) {
            minStr = DateUtilJava8.setTime(DateUtil.parse(synchronizationDataDate), 9, 0, 0);
            log.info("上班时间:{}", minStr);

            maxStr = DateUtilJava8.setTime(DateUtil.parse(synchronizationDataDate), 17, 0, 0);
            log.info("下班时间:{}", maxStr);

            middleStr = DateUtilJava8.setTime(DateUtil.parse(synchronizationDataDate), 12, 0, 0);
            log.info("判断是否早退迟到时间:{}", middleStr);

            queryDateStart = DateUtil.format(DateUtil.beginOfDay(DateUtil.parse(synchronizationDataDate)), "yyyy-MM-dd HH:mm:ss");

            queryDateEnd = DateUtil.format(DateUtil.endOfDay(DateUtil.parse(synchronizationDataDate)), "yyyy-MM-dd HH:mm:ss");
        } else {
            minStr = DateUtilJava8.setTime(DateUtil.parse(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd HH:mm:ss")), 9, 0, 0);
            log.info("上班时间:{}", minStr);

            maxStr = DateUtilJava8.setTime(DateUtil.parse(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd HH:mm:ss")), 17, 0, 0);
            log.info("下班时间:{}", maxStr);

            middleStr = DateUtilJava8.setTime(DateUtil.parse(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd HH:mm:ss")), 12, 0, 0);
            log.info("判断是否早退迟到时间:{}", middleStr);

            queryDateStart = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");

            queryDateEnd = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
        }

        QueryWrapper<AttendanceSign> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("sign_time", DateUtil.beginOfDay(DateUtil.parse(queryDateStart)));
        queryWrapper.le("sign_time", DateUtil.endOfDay(DateUtil.parse(queryDateEnd)));
        queryWrapper.eq("data_flag",0);
        queryWrapper.orderByAsc("name");
        queryWrapper.orderByAsc("sign_time");

        List<AttendanceSign> attendanceSigns = attendanceSignMapper.selectList(queryWrapper);

//        log.info("查询得数据：{}", JSONObject.toJSONString(attendanceSigns));

        Map<String, List<AttendanceSign>> groupedByNames = attendanceSigns.stream()
                .collect(Collectors.groupingBy(AttendanceSign::getUcUid));

        Map<String, Map<String, Object>> result = groupedByNames.entrySet().stream()
                .collect(Collectors.toMap(
                        item -> item.getKey(),
                        entry -> {
                            Map<String, Object> map = new HashMap<>();
                            List<AttendanceSign> list = entry.getValue();
                            map.put("minTime", Objects.requireNonNull(list.stream()
                                    .map(AttendanceSign::getSignTime) // 假设 getSignTime 是获取时间的方法
                                    .min(Comparator.naturalOrder()) // 计算最小时间
                                    .orElse(null)));
                            map.put("maxTime", Objects.requireNonNull(list.stream()
                                    .map(AttendanceSign::getSignTime)
                                    .max(Comparator.naturalOrder()) // 计算最大时间
                                    .orElse(null)));
                            return map;
                        }
                ));

//        log.info("处理得上下班时间：{}",JSONObject.toJSONString(result));

        List<AttendanceSign> distinctList = attendanceSigns.stream()
                .collect(Collectors.collectingAndThen(
                        Collectors.toCollection(() ->
                                new TreeSet<>(Comparator.comparing(AttendanceSign::getUcUid))  // 按UcUid去重
                        ),
                        ArrayList::new
                ));

// TODO处理保存对象

        // 查询工作日历表看是否为周末或法定节假日

        //获取工作日历表

        QueryWrapper<AttendanceCalendar> queryAttendanceCalendar = new QueryWrapper<>();
        queryAttendanceCalendar.apply("DATE_FORMAT(special_date, '%Y') >= {0}", DateUtil.year(DateUtil.parse(queryDateStart)));
        queryAttendanceCalendar.orderByDesc("special_date");


        List<AttendanceCalendar> attendanceCalendars = attendanceCalendarMapper.selectList(queryAttendanceCalendar);

        Map<Date, AttendanceCalendar> attendanceCalendarMap = attendanceCalendars.stream().collect(Collectors.toMap(AttendanceCalendar::getSpecialDate, item -> item));
//        log.info("工作日历map:{}", JSONObject.toJSONString(attendanceCalendarMap));

        QueryWrapper<EmpWorkPlan> queryWorkPlan = new QueryWrapper<>();
        queryWorkPlan.eq("work_date", DateUtil.beginOfDay(DateUtil.parse(queryDateStart)));

        List<EmpWorkPlan> empWorkPlanList = empWorkPlanMapper.selectList(queryWorkPlan);

//        log.info("请假表信息：{}",JSONObject.toJSONString(empWorkPlanList));
//        log.info("请假表总数：{}",JSONObject.toJSONString(empWorkPlanList.size()));

        Map<String, EmpWorkPlan> empWorkPlanMap = empWorkPlanList.stream().collect(Collectors.toMap(EmpWorkPlan::getUcUid, item -> item, (existing, replacement) -> existing));

        DateTime dateTime = DateUtil.parse(middleStr);


        String finalMiddleStr = middleStr;
        String finalMinStr = minStr;
        String finalMaxStr = maxStr;

        String finalQueryDateStart = queryDateStart;
        List<AttendanceStatistics> saveList = distinctList.stream().map(item -> {
            AttendanceStatistics attendanceStatistics = new AttendanceStatistics();
            attendanceStatistics.setUcUid(item.getUcUid());
            attendanceStatistics.setName(item.getName());
            attendanceStatistics.setCropId(item.getCropId());
            attendanceStatistics.setCropName(item.getCropName());
            attendanceStatistics.setDeptId(item.getDeptId());
            attendanceStatistics.setDeptName(item.getDeptName());
            Map<String, Object> stringObjectMap = result.get(item.getUcUid());

            if (!stringObjectMap.isEmpty()) {
                String minTime = stringObjectMap.get("minTime").toString();
                String maxTime = stringObjectMap.get("maxTime").toString();
                DateTime parseMin = DateUtil.parse(minTime);
                DateTime parseMax = DateUtil.parse(maxTime);
                attendanceStatistics.setSignDate(DateUtil.beginOfDay(parseMin));
                attendanceStatistics.setFirstSignTime(parseMin);
                attendanceStatistics.setLastSignTime(parseMax);

                StringJoiner sb = new StringJoiner(" ");

                // 先判断工作日历判断当前日期是否为周末或法定节假日

                AttendanceCalendar calendar = attendanceCalendarMap.get(DateUtil.beginOfDay(DateUtil.parse(finalQueryDateStart)));

                if (Objects.nonNull(calendar)) {
                    if ("WORKDAY".equals(calendar.getStatus())) {
                        sb.add("周末");
                    } else if ("HOLIDAY".equals(calendar.getStatus())) {
                        sb.add("法定节假日");
                    }
                } else {
                    boolean weekend = dateTime.isWeekend();
                    if (weekend) {
                        sb.add("周末");
                    } else {
                        if (attendanceStatistics.getFirstSignTime().getTime() == attendanceStatistics.getLastSignTime().getTime()) {
                            // 处理单次打卡情况

                            if (attendanceStatistics.getFirstSignTime().getTime() < DateUtil.parse(finalMiddleStr).getTime()) {
                                //只打了上班卡
                                sb.add("旷工");
                                attendanceStatistics.setLastSignTime(null);

                            } else if (attendanceStatistics.getLastSignTime().getTime() > DateUtil.parse(finalMiddleStr).getTime()) {
                                //只打了下班卡
                                sb.add("旷工");
                                attendanceStatistics.setFirstSignTime(null);
                            }
                        } else {
                            if (DateUtil.parse(finalMinStr).getTime() < parseMin.getTime()) {
                                //上班打卡时间不是9点
                                sb.add("迟到");
                            }
                            if (parseMax.getTime() < DateUtil.parse(finalMaxStr).getTime()) {
                                //下班打卡时间不是17点
                                sb.add("早退");
                            }

                            if (parseMin.getTime() <= DateUtil.parse(finalMinStr).getTime() && parseMax.getTime() >= DateUtil.parse(finalMaxStr).getTime()) {
                                sb.add("正常");
                            }
                        }
                    }
                }

                // 最后处理加班 请假状态
                EmpWorkPlan empWorkPlan = empWorkPlanMap.get(attendanceStatistics.getUcUid());
                if (Objects.nonNull(empWorkPlan)) {
                    String status = empWorkPlan.getStatus();
                    if ("年休假".equals(status)) {
//                        sb.add("");
                    } else {
                        if ("加班".equals(status)) {
                            sb.add("加班");
                        } else {
                            sb.add("请假");
                        }
                    }
                }
                attendanceStatistics.setSignStatus(sb.toString());
            }

            return attendanceStatistics;
        }).collect(Collectors.toList());

//        log.info("组装考勤统计表数据:{}", JSONObject.toJSONString(saveList));

        List<BatchResult> saveBatch = attendanceStatisticsMapper.insertOrUpdate(saveList);
        if (!saveBatch.isEmpty()) {
            log.info("考勤统计表保存成功");
        }
    }

    /**
     * 处理未打卡数据问题
     */
    private void unpunchedData() {
        LambdaQueryWrapper<Employee> lam = new LambdaQueryWrapper();
        lam.notIn(Employee::getUserStat, 1, 2, 3, 6, 7, 17, 26);
        lam.notIn(Employee::getUserType, 2, 3, 4, 6);
        //查询所有人员信息
        List<Employee> attendanceSigns = employeeMapper.selectList(lam);
//        log.info("用户总数：{}",  attendanceSigns.size());

        Map<String, Employee> employeeMap = attendanceSigns.stream()
                .collect(Collectors.toMap(Employee::getIdCardNum, item -> item, (existing, replacement) -> existing));


        //转换为list
        List<String> idCardNumAll = attendanceSigns.stream().map(Employee::getIdCardNum).collect(Collectors.toList());

        // 使用身份证查询用户详情信息

        QueryWrapper<GuserInfo> queryGuserInfo = new QueryWrapper<>();
        queryGuserInfo.in("ID_NUMBER", idCardNumAll);


        List<GuserInfo> guserInfos = guserInfoMapper.selectList(queryGuserInfo);
        List<String> gUserInfoIds = guserInfos.stream().map(GuserInfo::getId).collect(Collectors.toList());

        QueryWrapper<OaInSpurUser> queryOaInSpurUser = new QueryWrapper<>();
        queryOaInSpurUser.select("DISTINCT INSPUR_ID", "OAUSER_ID");
        queryOaInSpurUser.in("OAUSER_ID", gUserInfoIds);

        List<OaInSpurUser> oaInSpurUsers = oaInSpurUserMapper.selectList(queryOaInSpurUser).stream()
                .filter(ListUtil.distinctByKey(OaInSpurUser::getInspurId)).collect(Collectors.toList());

//        log.info("oaInSpurUsers:{}",oaInSpurUsers.size());

        Map<String, String> oaInSpurUserMap = oaInSpurUsers.stream().distinct().collect(Collectors.toMap(OaInSpurUser::getOaUserId, OaInSpurUser::getInspurId, (existing, replacement) -> existing));

//        log.info("oaInSpurUserMap:{}",JSONObject.toJSONString(oaInSpurUserMap));

        //所有用户集合
        List<String> allOaInSpuUserIds = oaInSpurUsers.stream().map(OaInSpurUser::getInspurId).collect(Collectors.toList());

        LambdaQueryWrapper<UmcUsers> usersLambdaQueryWrapper = new LambdaQueryWrapper<>();
        usersLambdaQueryWrapper.in(UmcUsers::getUcUid,allOaInSpuUserIds);
        List<UmcUsers> umcUsers = umcUserMapper.selectList(usersLambdaQueryWrapper);

        // 过滤掉禁用状态得账号
        allOaInSpuUserIds = umcUsers.stream().filter(item1 -> item1.getStatus().equals(11)).map(UmcUsers::getUcUid).collect(Collectors.toList());
        log.info("所有用户id数量：{}", allOaInSpuUserIds.size());

        Date now = null;

        if (StringUtils.isNotBlank(synchronizationDataDate)) {
            now = DateUtil.parse(synchronizationDataDate);
        } else {
            now = DateUtil.parse(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd HH:mm:ss"));
        }

        log.info("获取的配置时间：{}", DateUtil.beginOfDay(now));


        //获取今日已经打卡的用户id
        QueryWrapper<AttendanceSign> attendanceSignQuery = new QueryWrapper<>();
        attendanceSignQuery.select("DISTINCT  uc_uid");
        attendanceSignQuery.ge("sign_time", DateUtil.beginOfDay(now));
        attendanceSignQuery.le("sign_time", DateUtil.endOfDay(now));
        attendanceSignQuery.eq("data_flag",0);
        List<AttendanceSign> attendanceSignList = attendanceSignMapper.selectList(attendanceSignQuery);
        List<String> nowSignUcUids = attendanceSignList.stream().map(AttendanceSign::getUcUid).collect(Collectors.toList());

        log.info("考勤表中已打卡用户数量：{}", nowSignUcUids.size());


//        QueryWrapper<AttendanceStatistics> attendanceStatisticsQuery = new QueryWrapper<>();
//        attendanceStatisticsQuery.eq("sign_date",DateUtil.beginOfDay(now));
//        List<AttendanceStatistics> attendanceStatistics = attendanceStatisticsService.list(attendanceStatisticsQuery);
//        List<String> nowSignUcUids = attendanceStatistics.stream().map(AttendanceStatistics::getUcUid).toList();
//        log.info("已打卡的用户id:{}",JSONObject.toJSONString(nowSignUcUids));
//        log.info("已打卡用户数量:{}",nowSignUcUids.size());

        // 获取未打卡的用户id
        List<String> noSignForTheDayUcUids = getNoSignForTheDayUcUids(allOaInSpuUserIds, nowSignUcUids);

        noSignForTheDayUcUids = getNoneedToProcess(noSignForTheDayUcUids);

        log.info("未打卡用户id数量:{}", noSignForTheDayUcUids.size());

        //获取工作日历表

        QueryWrapper<AttendanceCalendar> queryAttendanceCalendar = new QueryWrapper<>();
        queryAttendanceCalendar.apply("DATE_FORMAT(special_date, '%Y') >= {0}", DateUtil.year(now));
        queryAttendanceCalendar.orderByDesc("special_date");


        List<AttendanceCalendar> attendanceCalendars = attendanceCalendarMapper.selectList(queryAttendanceCalendar);


        List<EmployeeDto> employeeDtoList = guserInfos.stream().map(item -> {
            EmployeeDto dto = new EmployeeDto();
            dto.setId(item.getId());
            dto.setIdCarNumber(item.getIdNumber()); //身份证号
            dto.setUcUid(oaInSpurUserMap.get(item.getId()));
            return dto;
        }).collect(Collectors.toList());

//        log.info("employeeDtoList:{}",JSONObject.toJSONString(employeeDtoList));

        Map<String, EmployeeDto> employeeDtoMap = employeeDtoList.stream().
                collect(Collectors.toMap(EmployeeDto::getUcUid, item -> item, (existing, replacement) -> existing));

//        log.info("employeeDtoMap:{}",JSONObject.toJSONString(employeeDtoMap));

        // 工作日历map
        Map<String, String> calendarMap = attendanceCalendars.stream().collect(Collectors.toMap(item -> DateUtil.format(item.getSpecialDate(), "yyyy-MM-dd"), AttendanceCalendar::getStatus));


        List<OaInspurOrganize> oaInspurOrganizes = oaInspurOrganizeMapper.selectList(null);
        Map<String, OaInspurOrganize> oaInspurOrganizeMap = oaInspurOrganizes.stream()
                .collect(Collectors.toMap(OaInspurOrganize::getInspurId, item -> item));
//        log.info("oaInspurOrganizes:{}",JSONObject.toJSONString(oaInspurOrganizes));
        List<Gorganize> gorganizes = gorganizeMapper.selectList(null);
        Map<String, String> gorganizeMap = gorganizes.stream().collect(Collectors.toMap(Gorganize::getId, Gorganize::getOrgName));
//        log.info("gorganizes:{}",JSONObject.toJSONString(gorganizes));


        QueryWrapper<EmpWorkPlan> queryWorkPlan = new QueryWrapper<>();
        queryWorkPlan.eq("work_date", DateUtil.beginOfDay(now));

        List<EmpWorkPlan> empWorkPlanList = empWorkPlanMapper.selectList(queryWorkPlan);

//        log.info("请假表信息：{}",JSONObject.toJSONString(empWorkPlanList));
//        log.info("请假表总数：{}",JSONObject.toJSONString(empWorkPlanList.size()));

        Map<String, EmpWorkPlan> empWorkPlanMap = empWorkPlanList.stream().collect(Collectors.toMap(EmpWorkPlan::getUcUid, item -> item,(existing, replacement) -> existing));

        // 处理数据未打卡得用户保存到考勤统计表
        Date finalNow = now;
        List<AttendanceStatistics> saveStatisticsList = noSignForTheDayUcUids.stream().map(item -> {

            AttendanceStatistics statistics = new AttendanceStatistics();
            statistics.setUcUid(item);
            EmployeeDto employeeDto = employeeDtoMap.get(item);

            if (Objects.nonNull(employeeDto)) {
                Employee employee = employeeMap.get(employeeDto.getIdCarNumber());
                if (Objects.nonNull(employee)) {
                    statistics.setName(employee.getUserName());
                    statistics.setCropId(employee.getUnitId());

                    OaInspurOrganize oaInspurOrganize = oaInspurOrganizeMap.get(employee.getUnitId());

                    if (Objects.nonNull(oaInspurOrganize)) {
                        String cropName = gorganizeMap.get(oaInspurOrganize.getOrgId());
                        statistics.setCropName(cropName);
                    }
                    statistics.setDeptId(employee.getDepartmentId());
                    OaInspurOrganize oaInspurOrganizeDept = oaInspurOrganizeMap.get(employee.getDepartmentId());
                    if (Objects.nonNull(oaInspurOrganizeDept)) {
                        String deptName = gorganizeMap.get(oaInspurOrganizeDept.getOrgId());
                        statistics.setDeptName(deptName);
                    }

                    statistics.setSignDate(DateUtil.beginOfDay(finalNow));
                    statistics.setFirstSignTime(null);
                    statistics.setLastSignTime(null);

                    //获取工作日历 如果为空就是正常工作日 如果不为空 值为 HOLIDAY（法定节假日） WORKDAY（周末）
                    String calendar = calendarMap.get(DateUtil.format(finalNow, "yyyy-MM-dd"));
                    StringBuffer sb = new StringBuffer();
                    if (StringUtils.isNotBlank(calendar)) {
                        if ("WORKDAY".equals(calendar)) {
                            sb.append("周末");
                        } else if ("HOLIDAY".equals(calendar)) {
                            sb.append("法定节假日");
                        }
                    } else {
                        // 旷工
                        boolean weekend = DateUtil.isWeekend(finalNow);
                        if (weekend) {
                            sb.append("周末");
                        } else {
                            sb.append("旷工");
                        }
                    }


                    // 除了加班全是请假
                    //（上下班时间调整、因公免签、已婚探望父母（四年一次，20天）、探望配偶（每年一次，30天））
                    //（新进人员免签、未婚探望父母（每年一次，20天）、婚假....）
                    if (!DateUtil.isWeekend(finalNow) && !StringUtils.isNotBlank(calendar)) {
                        EmpWorkPlan empWorkPlan = empWorkPlanMap.get(item);
                        if (Objects.nonNull(empWorkPlan)) {
                            String status = empWorkPlan.getStatus();
                            if ("年休假".equals(status)) {

                            } else {
                                if ("加班".equals(status)) {
                                    sb.append(" ").append("加班");
                                } else {
                                    sb.append(" ").append("请假");
                                }
                            }
                        }
                    }

                    statistics.setSignStatus(sb.toString());
                }
            }

            return statistics;
        }).collect(Collectors.toList());


//        AttendanceStatistics attendanceStatistics = saveStatisticsList.get(0);
//
//        log.info("保存考勤统计信息：{}",attendanceStatistics);

//        System.out.println("组装好保存考勤统计信息" + JSONArray.toJSONString(saveStatisticsList));

//        // 保存单个测试
//        boolean save = attendanceStatisticsService.save(attendanceStatistics);
//
//        if (save){
//            log.info("保存考勤统计表成功");
//        }

//         批量保存
        List<BatchResult> saveBatch = attendanceStatisticsMapper.insertOrUpdate(saveStatisticsList);
        if (!saveBatch.isEmpty()) {
            log.info("保存考勤统计表成功");
        }
//        for (AttendanceStatistics attendanceStatistics : saveStatisticsList) {
//            attendanceStatisticsMapper.insert(attendanceStatistics);
//        }


//
//        Path path = Paths.get("E:", "javaTask", synchronizationDataDate + "多数据源.txt");
//        //只保存id
//        List<String> saveIds = saveStatisticsList.stream().map(AttendanceStatistics::getUcUid).toList();
//        FileUtil.writeString(JSONObject.toJSONString(saveIds), path.toString(), "UTF-8");
//        log.info("文件写入成功路径为：{}", path.toString());
    }


    /**
     * 处理人员挂职单位逻辑
     */
    private void secondmentUnitsOfPerson() {
        String beginOfDay = "";
        String endOfDay = "";

        if (StringUtils.isNotBlank(synchronizationDataDate)) {
            beginOfDay = DateUtil.format(DateUtil.beginOfDay(DateUtil.parse(synchronizationDataDate)), "yyyy-MM-dd HH:mm:ss");
            endOfDay = DateUtil.format(DateUtil.endOfDay(DateUtil.parse(synchronizationDataDate)), "yyyy-MM-dd HH:mm:ss");
        } else {
            beginOfDay = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
            endOfDay = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
        }

        log.info("beginOfDay:{}----endOfDay:{}", beginOfDay, endOfDay);


        List<AttendancePersonnelUnit> attendancePersonnelUnits = attendancePersonnelUnitMapper.selectList(null);

        if (CollectionUtil.isNotEmpty(attendancePersonnelUnits)) {

            List<String> idList = attendancePersonnelUnits.stream().map(AttendancePersonnelUnit::getUcUid).collect(Collectors.toList());

            Map<String, AttendancePersonnelUnit> attendancePersonnelUnitMap = attendancePersonnelUnits.stream().collect(
                    Collectors.toMap(AttendancePersonnelUnit::getUcUid, item -> item, (existing, replacement) -> existing)
            );

            QueryWrapper<Employee> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("id", idList);

            List<Employee> employeeList = employeeMapper.selectList(queryWrapper);
            List<String> IdCardNum = employeeList.stream().map(Employee::getIdCardNum).collect(Collectors.toList());

            QueryWrapper<GuserInfo> queryGUserInfoWrapper = new QueryWrapper<>();
            queryGUserInfoWrapper.in("ID_NUMBER", IdCardNum);

            List<GuserInfo> guserInfoList = guserInfoMapper.selectList(queryGUserInfoWrapper);

            Map<String, GuserInfo> guserInfoMap = guserInfoList.stream().collect(Collectors.toMap(GuserInfo::getId, item -> item));

            List<String> gUserInfoIds = guserInfoList.stream().map(GuserInfo::getId).collect(Collectors.toList());

            QueryWrapper<OaInSpurUser> queryOaSpurUserWrapper = new QueryWrapper<>();
            queryOaSpurUserWrapper.in("OAUSER_ID", gUserInfoIds);


            List<OaInSpurUser> oaInSpurUsers = oaInSpurUserMapper.selectList(queryOaSpurUserWrapper);

            List<OaInSpurUserDto> oaInSpurUserDtos = oaInSpurUsers.stream().map(item -> {

                OaInSpurUserDto dto = new OaInSpurUserDto();
                dto.setOaUserId(item.getOaUserId());
                dto.setInSpurId(item.getInspurId());
                GuserInfo guserInfo = guserInfoMap.get(item.getOaUserId());

                if (Objects.nonNull(guserInfo)) {
                    dto.setIdNumber(guserInfo.getIdNumber());
                }

                return dto;
            }).distinct().collect(Collectors.toList());


            Map<String, OaInSpurUserDto> stringOaInSpurUserDtoMap = oaInSpurUserDtos.stream().collect(
                    Collectors.toMap(OaInSpurUserDto::getIdNumber, item -> item, (existing, replacement) -> existing)
            );

//        log.info("人员挂职基本信息：{}" , JSONArray.toJSONString(employeeList));

            List<AttendancePersonnelUnitDto> attendancePersonnelUnitDtos = employeeList.stream().map(item -> {
                AttendancePersonnelUnitDto dto = new AttendancePersonnelUnitDto();
                dto.setId(item.getId());
                AttendancePersonnelUnit attendancePersonnelUnit = attendancePersonnelUnitMap.get(item.getId());
                if (Objects.nonNull(attendancePersonnelUnit)) {
                    dto.setUnitId(attendancePersonnelUnit.getUnitId());
                    dto.setUnitName(attendancePersonnelUnit.getUnitName());
                    dto.setDeptId(attendancePersonnelUnit.getDeptId());
                    dto.setDeptName(attendancePersonnelUnit.getDeptName());

                    OaInSpurUserDto oaInSpurUserDto = stringOaInSpurUserDtoMap.get(item.getIdCardNum());
                    dto.setUcUid(oaInSpurUserDto.getInSpurId());
                }
                return dto;
            }).collect(Collectors.toList());


//        log.info("挂职人员组装好要修改的数据:{}", JSONArray.toJSONString(attendancePersonnelUnitDtos));

            if (!attendancePersonnelUnitDtos.isEmpty()) {
                for (AttendancePersonnelUnitDto attendancePersonnelUnitDto : attendancePersonnelUnitDtos) {
                    AttendanceSign attendanceSign = new AttendanceSign();
                    attendanceSign.setCropId(attendancePersonnelUnitDto.getUnitId());
                    attendanceSign.setCropName(attendancePersonnelUnitDto.getUnitName());
                    attendanceSign.setDeptId(attendancePersonnelUnitDto.getDeptId());
                    attendanceSign.setDeptName(attendancePersonnelUnitDto.getDeptName());
                    attendanceSign.setUcUid(attendancePersonnelUnitDto.getUcUid());

                    UpdateWrapper<AttendanceSign> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.set("crop_id", attendanceSign.getCropId());
                    updateWrapper.set("crop_name", attendanceSign.getCropName());
                    updateWrapper.set("dept_id", attendanceSign.getDeptId());
                    updateWrapper.set("dept_name", attendanceSign.getDeptName());
                    updateWrapper.eq("uc_uid", attendanceSign.getUcUid());
                    int update = attendanceSignMapper.update(updateWrapper);
                    if (update > 0) {
                        log.info("修改考勤表成功,ucUid:{}", attendanceSign.getUcUid());
                    }
                }

                for (AttendancePersonnelUnitDto attendancePersonnelUnitDto : attendancePersonnelUnitDtos) {
                    AttendanceStatistics attendanceStatistics = new AttendanceStatistics();
                    attendanceStatistics.setCropId(attendancePersonnelUnitDto.getUnitId());
                    attendanceStatistics.setCropName(attendancePersonnelUnitDto.getUnitName());
                    attendanceStatistics.setDeptId(attendancePersonnelUnitDto.getDeptId());
                    attendanceStatistics.setDeptName(attendancePersonnelUnitDto.getDeptName());
                    attendanceStatistics.setUcUid(attendancePersonnelUnitDto.getUcUid());

                    UpdateWrapper<AttendanceStatistics> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.set("crop_id", attendanceStatistics.getCropId());
                    updateWrapper.set("crop_name", attendanceStatistics.getCropName());
                    updateWrapper.set("dept_id", attendanceStatistics.getDeptId());
                    updateWrapper.set("dept_name", attendanceStatistics.getDeptName());
                    updateWrapper.eq("uc_uid", attendanceStatistics.getUcUid());
                    int update = attendanceStatisticsMapper.update(updateWrapper);
                    if (update > 0) {
                        log.info("修改考勤统计表成功,ucUid:{}", attendanceStatistics.getUcUid());
                    }
                }
            }
        }
    }

    /**
     * 获取今日未打卡的UcUid
     *
     * @return
     */
    public List<String> getNoSignForTheDayUcUids(List<String> allUcUids, List<String> nowSignUcUids) {

        return allUcUids.stream()
                .filter(e -> !nowSignUcUids.contains(e))  // 过滤掉在 list2 中存在的元素
                .collect(Collectors.toList());
    }

    /**
     * 获取不需要处理打卡的UcUid
     */
    public List<String> getNoneedToProcess(List<String> allUcUids) {

        List<String> userTypes = Arrays.asList("2", "4", "6");
        List<String> userStat = Arrays.asList("1", "14", "15", "16", "17", "18", "2", "21", "3", "6", "7");

        QueryWrapper<Employee> queryEmployeeWrapper = new QueryWrapper<>();
        queryEmployeeWrapper.in("USER_TYPE", userTypes);
        queryEmployeeWrapper.in("USER_STAT", userStat);

        List<Employee> employees = employeeMapper.selectList(queryEmployeeWrapper);

        List<String> employeeIdCardNums = employees.stream().map(Employee::getIdCardNum).collect(Collectors.toList());

        QueryWrapper<GuserInfo> queryGuserInfoWrapper = new QueryWrapper<>();
        queryGuserInfoWrapper.in("ID_NUMBER", employeeIdCardNums);

        List<GuserInfo> guserInfos = guserInfoMapper.selectList(queryGuserInfoWrapper);

        List<String> gUserInfoIds = guserInfos.stream().map(GuserInfo::getId).collect(Collectors.toList());

        QueryWrapper<OaInSpurUser> queryOaInSpurUser = new QueryWrapper<>();
        queryOaInSpurUser.in("OAUSER_ID", gUserInfoIds);

        List<OaInSpurUser> oaInSpurUsers = oaInSpurUserMapper.selectList(queryOaInSpurUser);

        List<String> noNeedToProcess = oaInSpurUsers.stream().map(OaInSpurUser::getInspurId).collect(Collectors.toList());

//        log.info("不需要处理打卡的UcUid:{}",JSONObject.toJSONString(noNeedToProcess));

        return getNoSignForTheDayUcUids(allUcUids, noNeedToProcess);
    }


    private void noSignData() {
        DateTime yesterday = null;
        if (StringUtils.isNotBlank(synchronizationDataDate)) {
            yesterday = DateUtil.parse(synchronizationDataDate);
        } else {
            yesterday = DateUtil.yesterday();
        }


        log.info("昨天日期：{}", DateUtil.beginOfDay(yesterday));

        List<AttendanceSignAndStatisticsConfigEntity> attendanceSignAndStatisticsDtoList = updateAttendanceSignDto.getAttendanceSignAndStatisticsDtoList();
        log.info("获取到的配置文件中要处理的当日考勤数量：{}", attendanceSignAndStatisticsDtoList.size());

        if (!attendanceSignAndStatisticsDtoList.isEmpty()) {
            //处理考勤表数据
            List<AttendanceSign> updateSignList = attendanceSignAndStatisticsDtoList.stream().map(item -> {

                AttendanceSign attendanceSign = new AttendanceSign();
                attendanceSign.setUcUid(item.getUcUid());
                attendanceSign.setName(item.getName());

                return attendanceSign;
            }).collect(Collectors.toList());

            // 修改考勤表数据

            for (AttendanceSign attendanceSign : updateSignList) {
                if (StringUtils.isNotBlank(attendanceSign.getName())) {
                    UpdateWrapper<AttendanceSign> updateSignWrapper = new UpdateWrapper<>();
                    updateSignWrapper.set("uc_uid", attendanceSign.getUcUid());
                    updateSignWrapper.eq("name", attendanceSign.getName());
                    updateSignWrapper.ge("sign_time", DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
                    updateSignWrapper.le("sign_time", DateUtil.format(DateUtil.endOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));

                    int update = attendanceSignMapper.update(attendanceSign, updateSignWrapper);

                    if (update > 0) {
                        log.info("name为：{}，考勤表信息修改成功,日期：{}", attendanceSign.getName(),
                                DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
                    }
                }

            }

            List<AttendanceStatistics> attendanceStatisticsList = attendanceSignAndStatisticsDtoList.stream().map(item -> {
                AttendanceStatistics attendanceStatistics = new AttendanceStatistics();
                attendanceStatistics.setUcUid(item.getUcUid());
                attendanceStatistics.setName(item.getName());
                return attendanceStatistics;
            }).collect(Collectors.toList());

            for (AttendanceStatistics attendanceStatistics : attendanceStatisticsList) {
                if (StringUtils.isNotBlank(attendanceStatistics.getName())) {


                    UpdateWrapper<AttendanceStatistics> updateStatisticsWrapper = new UpdateWrapper<>();
                    updateStatisticsWrapper.set("crop_id", attendanceStatistics.getCropId());
                    updateStatisticsWrapper.eq("name", attendanceStatistics.getName());
                    updateStatisticsWrapper.eq("sign_date", DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));

                    int update = attendanceStatisticsMapper.update(attendanceStatistics, updateStatisticsWrapper);
                    if (update > 0) {
                        log.info("name为：{}，考勤统计表信息修改成功,日期：{}", attendanceStatistics.getName(),
                                DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
                    }
                }
            }


            // 修改考勤统计表数据
            List<AttendanceStatistics> updateStatisticsList = attendanceSignAndStatisticsDtoList.stream().map(item -> {
                AttendanceStatistics attendanceStatistics = new AttendanceStatistics();
                attendanceStatistics.setCropId(item.getCropId());
                attendanceStatistics.setCropName(item.getCropName());
                attendanceStatistics.setDeptId(item.getDeptId());
                attendanceStatistics.setDeptName(item.getDeptName());
                attendanceStatistics.setName(item.getStatisticsName());
                return attendanceStatistics;
            }).collect(Collectors.toList());

            for (AttendanceStatistics attendanceStatistics : updateStatisticsList) {
                if (StringUtils.isNotBlank(attendanceStatistics.getName())) {
                    UpdateWrapper<AttendanceStatistics> updateAttendanceStatisticsWrapper = new UpdateWrapper<>();
                    updateAttendanceStatisticsWrapper.set("crop_id", attendanceStatistics.getCropId());
                    updateAttendanceStatisticsWrapper.set("crop_name", attendanceStatistics.getCropName());
                    updateAttendanceStatisticsWrapper.set("dept_id", attendanceStatistics.getDeptId());
                    updateAttendanceStatisticsWrapper.set("dept_name", attendanceStatistics.getDeptName());
                    updateAttendanceStatisticsWrapper.eq("name", attendanceStatistics.getName());
                    updateAttendanceStatisticsWrapper.eq("sign_date", DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
                    int update = attendanceStatisticsMapper.update(attendanceStatistics, updateAttendanceStatisticsWrapper);
                    if (update > 0) {
                        log.info("name为：{}，考勤统计表信息修改成功,日期：{}", attendanceStatistics.getName(),
                                DateUtil.format(DateUtil.beginOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"));
                    }

                }
            }
        }
    }

    /**
     * 处理挂职单位考勤数据
     */
    private void handleAttendanceDataOfTheSecondedUnit() {
        log.info("开始处理挂职单位当日考勤数据");
        String beginOfDay = "";
        String endOfDay = "";

        beginOfDay = DateUtil.format(DateUtil.beginOfDay(DateUtil.parse(DateUtil.now())), "yyyy-MM-dd HH:mm:ss");
        endOfDay = DateUtil.format(DateUtil.endOfDay(DateUtil.parse(DateUtil.now())), "yyyy-MM-dd HH:mm:ss");

        log.info("beginOfDay:{}----endOfDay:{}", beginOfDay, endOfDay);

//        QueryWrapper<AttendancePersonnelUnit> queryUnitWrapper = new QueryWrapper<>();
//        queryUnitWrapper.eq("uc_uid", "766df88a380940a490334fafebb269e6");

        List<AttendancePersonnelUnit> attendancePersonnelUnits = attendancePersonnelUnitMapper.selectList(null);

        if (CollectionUtil.isNotEmpty(attendancePersonnelUnits)) {

            for (AttendancePersonnelUnit attendancePersonnelUnit : attendancePersonnelUnits) {

                QueryWrapper<Employee> queryWrapper = new QueryWrapper<>();
                queryWrapper.in("id", attendancePersonnelUnit.getUcUid());

                Employee employee = employeeMapper.selectOne(queryWrapper);

                if (Objects.nonNull(employee)) {
                    QueryWrapper<UmcPerson> queryUserPersonWrapper = new QueryWrapper<>();
                    queryUserPersonWrapper.in("cert_num", employee.getIdCardNum());

                    UmcPerson umcPerson = umcPersonMapper.getUcUidByCertNum(employee.getIdCardNum());
                    // status 10：禁用 11：启用
                    if(umcPerson.getStatus().equals("10")){
                        log.warn("用户为：{}，账号已禁用，不处理当日考勤",umcPerson.getUName());
                        // 执行下一次循环
                        continue;
                    }
                    QueryWrapper<AttendanceSign> querySignWrapper = new QueryWrapper<>();
                    querySignWrapper.ge("sign_time", DateUtil.beginOfDay(DateUtil.parse(beginOfDay)));
                    querySignWrapper.le("sign_time", DateUtil.endOfDay(DateUtil.parse(endOfDay)));
                    querySignWrapper.eq("uc_uid", umcPerson.getUcUid());
                    querySignWrapper.eq("data_flag",0);
                    querySignWrapper.orderByAsc("name");
                    querySignWrapper.orderByAsc("sign_time");

                    List<AttendanceSign> attendanceSigns = attendanceSignMapper.selectList(querySignWrapper);

                    if (CollectionUtil.isNotEmpty(attendanceSigns)) {
                        for (AttendanceSign attendanceSign : attendanceSigns) {

                            QueryWrapper<AttendanceSign> querySignRepeatWrapper = new QueryWrapper<>();
                            querySignRepeatWrapper.ge("sign_time", DateUtil.beginOfDay(DateUtil.parse(beginOfDay)));
                            querySignRepeatWrapper.le("sign_time", DateUtil.endOfDay(DateUtil.parse(endOfDay)));
                            querySignRepeatWrapper.eq("uc_uid", attendancePersonnelUnit.getUcUid());
                            querySignRepeatWrapper.eq("sign_time", DateUtil.parse(DateUtil.format(attendanceSign.getSignTime(), "yyyy-MM-dd HH:mm:ss")));
                            querySignRepeatWrapper.eq("data_flag",1);

                            List<AttendanceSign> attendanceSignsBySignTime = attendanceSignMapper.selectList(querySignRepeatWrapper);

                            if (CollectionUtil.isEmpty(attendanceSignsBySignTime)) {
                                // 组装考勤信息
                                AttendanceSign saveAttendanceSign = new AttendanceSign();
                                saveAttendanceSign.setUcUid(attendancePersonnelUnit.getUcUid());
                                saveAttendanceSign.setName(attendanceSign.getName());
                                saveAttendanceSign.setCropId(attendancePersonnelUnit.getUnitId());
                                saveAttendanceSign.setCropName(attendancePersonnelUnit.getUnitName());
                                saveAttendanceSign.setDeptId(attendancePersonnelUnit.getDeptId());
                                saveAttendanceSign.setDeptName(attendancePersonnelUnit.getDeptName());
                                saveAttendanceSign.setLocation(attendanceSign.getLocation());
                                saveAttendanceSign.setPosition(attendanceSign.getPosition());
                                saveAttendanceSign.setSignTime(attendanceSign.getSignTime());
                                saveAttendanceSign.setDataFlag(1); // 挂职单位当日考勤数据
                                int insert = attendanceSignMapper.insert(saveAttendanceSign);
                                log.info("处理挂职单位当日考勤数据成功：name：{},uc_uid:{}", saveAttendanceSign.getName(), saveAttendanceSign.getUcUid());

                            }

                        }
                    }
                }
            }
        }
    }
}
